package org.example.config;//package com.zaxh.config;
//
//import com.google.code.shardbatis.plugin.ShardPlugin;
//import org.apache.ibatis.plugin.Interceptor;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//
//import javax.sql.DataSource;
//import java.util.Properties;
//
//@Configuration
//@MapperScan(basePackages = "com.zaxh.mapper", sqlSessionFactoryRef = "sqlSessionFactory")
//public class DatasourceConfig {
//
//    // 省略dataSource配置等相关代码
//
//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
//
//        try {
//            final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//            sessionFactory.setDataSource(dataSource);
//            sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*Mapper.xml"));
//            sessionFactory.setPlugins(new Interceptor[] { getShardPlugin() });
//
//            return sessionFactory.getObject();
//        } catch (Exception e) {
//            throw new RuntimeException("sqlSessionFactory configuration error", e);
//        }
//    }
//
//    private Interceptor getShardPlugin() {
//
//        Properties properties = new Properties();
//        properties.setProperty("shardingConfig", "shard_config.xml");
//
//        ShardPlugin shardPlugin = new ShardPlugin();
//        shardPlugin.setProperties(properties);
//
//        return shardPlugin;
//    }
//}